Array.prototype.remove=function(dx){
	if(isNaN(dx)||dx>this.length){return false;}
	for(var i=0,n=0;i<this.length;i++)
	{
	    if(this[i]!=this[dx])
	    {
	        this[n++]=this[i]
	    }
	}
	this.length-=1;
}

var x=0;
var y=0;

mainPanelWidth = document.body.clientWidth;
mainPanelHeight = document.body.clientHeight;

var count = 0;
var count2 = 0;
var count3 = 0;
//var crmStyle = new style();

function callWeb(node, event, url, panel) {
	var n = main.getComponent("menuId_"+node.id);
	if (!n) {
			
		sysModeLoader.baseParams['sysComId']=node.id;
		sysModeLoader.baseParams['type']=2;
		sysModeLoader.removeAll();
		sysModeLoader.load({params:{},callback:function(r,options,success){
			if(success){
				if(node.id==62){
					main.openTab(node, event, panel,r);
				}else{
					if(r && r.length>0){
						main.openTab(node, event, panel,r);
					}else{
						Ext.Msg.alert("提示","对不起，您没有相关权限！")
					}
				}
			}
		}});
	}else{
		main.openTab(node, event, panel,[]);
	}
}
var header, basePanel, menu, copyright,count=0,flag=true,flag2=true,flag3=true,flag4=true,count02=0,flag02=true;
// 客户管理

tabContent = function() {
	this.openTab = function(node, event, panel,r) {
		var n = main.getComponent("menuId_"+node.id);
		if (!n) {
			if(main.items.length>=10){
				Ext.MessageBox.alert("提示","对不起，您打开的窗口过多，请关闭后重试！");
				return;
			}
			var p = new panel({
				authArray:r,
				id:"menuId_"+node.id,
                sysComId:node.attributes.sysComId,
				defaults:{bodyStyle: panelMainStyle},
				bodyStyle: my_scroll_cs
			});
			p.title = node.text;
			n = main.add(p);
		}
		main.setActiveTab(n);
//		main.on('beforeremove',function(c1, c2){
//			if(c2.canClose != undefined){
//				if(c2.canClose == true){
//					return true;
//				}else{
//					var flag = false;
//					Ext.MessageBox.confirm("提示","您确认要放弃对当前数据的维护吗?",function(o){
//						if(o =='yes'){
//							c2.canClose = true;
//							c1.remove(c2);
//						}
//					});
//					return flag;
//				}
//			}else{
//				return true;
//			}
//		});
		main.on("contextmenu",function(tabContent,n,e){
			if(n.id=='system'){
				var menu=new Ext.menu.Menu([{
	                text:"关闭其他所有页",
	                handler:function(){
	                tabContent.items.each(function(item){
							if(item.closable&&item!=n)
							{
							   tabContent.remove(item);
							}
	                	});
	                }
	            }]);
			}else{
				var menu=new Ext.menu.Menu([{
                              text:"关闭当前页",
                              handler:function(){
                                 tabContent.remove(n);
                              }
                     },{
                          text:"关闭其他所有页",
                          handler:function(){
                             tabContent.items.each(function(item){
                              if(item.closable&&item!=n)
                              {
                                 tabContent.remove(item);
                              }
                             });
                          }
                     }
                     ]);
			}
    		menu.showAt(e.getPoint());
		});
		main.doLayout();
	};

	
	tabContent.superclass.constructor.call(this, {
		id : 'main',
		region : 'center',
		margins : '0 3 3 3',
		autoTabs : true,
		enableTabScroll : true,
		activeTab : 0,
		items : {
			title : '系统介绍',
			id:'system',
			closable : false,
			html : '<div style="position:absolute; left:10%; top:15%;"><img width="880" height="452" src='+basepath+'/imgs/main.jpg /><br /></div>'
		}
	});
	
}
Ext.extend(tabContent, Ext.TabPanel);
header = new Ext.Panel({
	border : false,
	region : 'north',
	height : 59,
	frame : false,
	layout:'fit',
	items : [
		{frame:false,border : false,html : '<div width="490" style="float:left;"><img src="'+basepath+'/imgs/header_log.png" height="83" /></div><div class="index_logo" style="width:auto;float:right;">' +
		'<div><div style="padding-top:40px;" align="right"><span style="width:100%;font-size:12px;font-weight:bold;padding-right:10px;">' +
		'<img src="'+basepath+'/imgs/index_ico1.gif" /><font color="0065cc">&nbsp;&nbsp;当前使用者：'+realName+'&nbsp;' +
		'&nbsp;</font><a id="logoutId" href="javascript:showModifyPsWin();"><font color="bf0000">修改密码</font></a>&nbsp;&nbsp;<a id="logoutId" href="javascript:loginOut();"><font color="bf0000">退出</font></a></span>' +
		'</div></div></div>'}
		]
	});
if(Ext.isIE){//ie
header = new Ext.Panel({
	border : false,
	region : 'north',
	height : 59,
	frame : false,
	layout:'fit',
	items : [
		{frame:false,border : false,html : '<div width="490" style="float:left;"><img src="'+basepath+'/imgs/header_log.gif" height="83" /></div>' +
		'<div class="index_logo" style="width:auto;float:right;">' +
		'<div style="padding-top:40px;" align="right"><span style="width:100%;font-size:12px;font-weight:bold;padding-right:10px;">' +
		'<img src="'+basepath+'/imgs/index_ico1.gif" /><font color="0065cc">&nbsp;&nbsp;当前使用者：'+realName+'&nbsp;' +
		'&nbsp;</font><a id="logoutId" href="javascript:showModifyPsWin();"><font color="bf0000">修改密码</font></a>&nbsp;&nbsp;<a id="logoutId" href="javascript:loginOut();"><font color="bf0000">退出</font></a></span>' +
		'</div></div>'
                }
		]
	});
}
if(Ext.isGecko){//firefox
header = new Ext.Panel({
	border : false,
	region : 'north',
	height : 59,
	frame : false,
	layout:'fit',
	items : [
		{frame:false,border : false,html : '<div width="50" style="float:left;"><img src="'+basepath+'/imgs/header_log.png" height="83" /></div><div class="index_logo" style="width:auto;float:right;">' +
		'<div><div style="padding-top:40px;" align="right"><span style="width:100%;font-size:12px;font-weight:bold;padding-right:10px;">' +
		'<img src="'+basepath+'/imgs/index_ico1.gif" /><font color="0065cc">&nbsp;&nbsp;当前使用者：'+realName+'&nbsp;' +
		'&nbsp;</font><a id="logoutId" href="javascript:showModifyPsWin();"><font color="bf0000">修改密码</font></a>&nbsp;&nbsp;<a id="logoutId" href="javascript:loginOut();"><font color="bf0000">退出</font></a></span>' +
		'</div></div></div>'}
		]
	});
}

// 显示修改密码面板
function showModifyPsWin() {
	var oldPassword = new Ext.form.TextField({
		id:'oldPassword',
		inputType: 'password',
		maxLength: 16,
		minLength: 3,
		allowBlank : false
	});	
	var newPassword = new Ext.form.TextField({
		id:'newPassword',
		inputType: 'password',
		maxLength: 16,
		minLength: 3,
		allowBlank : false
	});	
	var confirmPassword = new Ext.form.TextField({
		id:'confirmPassword',
		inputType: 'password',
		maxLength: 16,
		minLength: 3,
		allowBlank : false
	});	
	var win;
	var panel = new Ext.Panel({
		frame: true,
		buttonAlign: 'center',
		buttons: [
			{
				text:'确定',
				handler: function(){
					if(oldPassword.validate() && newPassword.validate() && confirmPassword.validate()){
						if(newPassword.getValue() != confirmPassword.getValue()){
							Ext.Msg.alert("提示","新密码与确认密码不同,请重新输入并确认.",function(){
								confirmPassword.setValue('');
								newPassword.selectText();
								newPassword.focus();
							});
							return;
						}else{
							showProgress();
							Ext.Ajax.request({
								url : basepath+'/ecerp/ecerpLogin/updateSysMemberPassword.html',
								params : {
									oldPassword : oldPassword.getValue(),
									newPassword : newPassword.getValue(),
									confirmPassword : confirmPassword.getValue()
								},
								callback:function(options,success,response){
									var m =Ext.decode(response.responseText);
									if(m.success){
										Ext.Msg.alert('提示','密码修改成功',function(){
											win.close();
										});
									}else{
										Ext.Msg.alert("提示", m.msg,function(){
											oldPassword.selectText();
											oldPassword.focus();
										});
									}
								}
							});
						}
					}
				}
			},	
			{
				text:'取消',
				handler: function(){
					win.close();
				}
			}	
		],
		layout:'table',
		layoutConfig: {columns:2},
		items:[
			{html:'<span style="font-size:12px;color:#3968AC">&nbsp;&nbsp;&nbsp;&nbsp;旧&nbsp;&nbsp;密&nbsp;码:&nbsp;</span>'},
			oldPassword,
			{height:5,colspan:2},
			{html:'<span style="font-size:12px;color:#3968AC">&nbsp;&nbsp;&nbsp;&nbsp;新&nbsp;&nbsp;密&nbsp;码:&nbsp;</span>'},
			newPassword,
			{height:5,colspan:2},
			{html:'<span style="font-size:12px;color:#3968AC">&nbsp;&nbsp;&nbsp;&nbsp;确认密码:&nbsp;</span>'},
			confirmPassword
		]
	});
	
	win = new Ext.Window({
		frame: true,
		width: 250,
		title: '密码修改',
		items:[panel]
	});
	win.show();
}
function loginOut(){
	Ext.Msg.show({
		title:'提示',
		msg: '您确认要登出系统么，继续请确定?',
		buttons:{ok:'确定',cancel:'取消'},
		fn: function(obj){
			if(obj=="ok"){
				window.location.replace(basepath+'/auth/sysMemberLoginout.html');
			}
		}
	});
}
//一些公用方法
var mainMessageBox;
function showProgress(){
	mainMessageBox = Ext.MessageBox.show({
		title:'系统提示',
	  	msg: '请稍候...',
		progressText: '',
		width:230,
		wait:true,
		waitConfig: {interval:700}
	});
}

function getCompetenceForAllDev(anthArray,competenceId){
//	var flag = false;
//	Ext.each(anthArray, function(ar) {
//		if(ar.data.id == competenceId) {
//			flag = true;
//		}
//	});
//	return flag;
    return true;
}

function showNewTabPanel(title,tpId,panel,data,index,fatherPanel){
	var n = main.getComponent("newTab_"+tpId);
	if (!n) {
		if(main.items.length>=10){
			Ext.MessageBox.alert("提示","对不起，您打开的窗口过多，请关闭后重试！");
			return;
		}
		var p = new panel({
			data: data,
			id : "newTab_"+tpId,
			defaults: {bodyStyle: panelMainStyle},
			bodyStyle: my_scroll_cs,
			fatherPanel : fatherPanel
		});
		p.title = title;
		if(index){
			n = main.insert(index,p);
		}
		else{
			n = main.add(p);
		}
	}
	main.setActiveTab(n);
	main.doLayout();
}

function checkBoxAll(obj){
	for (var i = 0; i < document.getElementsByName(obj.name.substring(2)).length; i++) {
		document.getElementsByName(obj.name.substring(2))[i].checked =document.getElementById(obj.name).checked;
	}
}

function checkBoxSingle(obj){
	for (var i=0; i<document.getElementsByName(obj.name).length; i++){
		 if(false==document.getElementsByName(obj.name)[i].checked){
			document.getElementById("p_"+obj.name).checked=false;
			return;
		}
	}
	document.getElementById("p_"+obj.name).checked=true;
}
MsgTip = function(){
    var msgCt;
    function createBox(t, s){
        return ['<div class="msg">',
                '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
                '<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc" style="font-size=12px;"><h3>', t, '</h3>', s, '</div></div></div>',
                '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
                '</div>'].join('');
    }
    return {
        msg : function(title, message,width,autoHide,pauseTime){
            if(!msgCt){
            	if(!width) width = 300;
                msgCt = Ext.DomHelper.insertFirst(document.body, {id:'msg-div22',style:'position:absolute;top:10px;width:'+width+'px;margin:0 auto;z-index:20000;'}, true);
            }
            msgCt.alignTo(document, 't-t');
             var s = String.format.apply(String, Array.prototype.slice.call(arguments, 1));
            var m = Ext.DomHelper.append(msgCt, {html:createBox(title, s)}, true);
            m.slideIn('t').pause(1).ghost("t", {remove:true});
        },
        hide:function(v){
         var msg=Ext.get(v.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement);
         msg.ghost("tr", {remove:true});
        }
    };
}();